package com.psmz.iwi.docanalyzer.ui;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import javax.swing.table.AbstractTableModel;

import com.psmz.iwi.docanalyzer.core.document.entities.DocumentSearchResult;

public class ResultTableModel extends AbstractTableModel {

	private static final int NUMBER_OF_COLUMNS = 2;
	private static final String[] COLUMN_NAMES = new String[] { "Dokument",
			"Dopasowanie" };
	private List<DocumentSearchResult> resultList = new ArrayList<DocumentSearchResult>();

	public ResultTableModel(Collection<DocumentSearchResult> resultList) {
		this.resultList = new ArrayList<DocumentSearchResult>(resultList);
	}

	@Override
	public int getRowCount() {
		return resultList.size();
	}

	@Override
	public int getColumnCount() {
		return NUMBER_OF_COLUMNS;
	}

	@Override
	public String getColumnName(int columnIndex) {
		return COLUMN_NAMES[columnIndex];
	}

	@Override
	public Class<?> getColumnClass(int columnIndex) {
		return String.class;
	}

	@Override
	public boolean isCellEditable(int rowIndex, int columnIndex) {
		return false;
	}

	@Override
	public Object getValueAt(int rowIndex, int columnIndex) {
		DocumentSearchResult searchResult = resultList.get(rowIndex);
		String value = null;
		switch (columnIndex) {
		case 0:
			value = searchResult.getPath();
			break;
		case 1:
			value = String.valueOf(searchResult.getScore());
			break;
		default:
			break;
		}
		return value;
	}

	public void reloadData(
			Collection<DocumentSearchResult> documentFullTextSearch) {
		this.resultList = new ArrayList<DocumentSearchResult>(
				documentFullTextSearch);
		fireTableDataChanged();

	}

}
